package com.yiqi.liebang.feature.order.view;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.TabEntity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class OrderActivity extends BaseActivity {

    @BindView(R.id.container_view)
    ViewPager mContainerView;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    @BindView(R.id.tl_4)
    SlidingTabLayout mTabLayout_2;
    private String[] mTitles = { "话题","问答"};
    int[] mIconSelectIds = {
            R.drawable.btn_huati, R.drawable.btn_wenda,
    };

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_order;
    }

    @Override
    protected void initInjector() {

    }


    @Override
    public void initView() {
        mFragments.add(new OrderTopicFragment());
        mFragments.add(new OrderQuestionFragment());



        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconSelectIds[i]));
        }
        MyPagerAdapter   mAdapter = new MyPagerAdapter(this.getSupportFragmentManager());
        mContainerView.setAdapter(mAdapter);
        mTabLayout_2.setViewPager(mContainerView, mTitles, this, mFragments);

    }

    @Override
    protected void initData() {
    }


    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }

    private class MyPagerAdapter extends FragmentStatePagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }


}